<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="../js/mui.js"></script>
		<link href="../css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/header.css" />

		<style>
			#btn_add_friend {
	        	background-color: #1aad19;
	        }
	        #btn_add_friend:active {
	            background-color: #128e12;
	        }
		</style>
	</head>

	<body >

		<header class="mui-bar mui-bar-nav title" style="position: fixed;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left title-color"></a>
			<h1 class="mui-title title-color"><b id="chatting-nickname">详细资料</b></h1>
		</header>
		
		<div class="mui-content">
			
			<ul class="mui-table-view">
			    <li class="mui-table-view-cell mui-media" style="padding-top: 10px;">
			        <a href="javascript:;">
			            <img id="img_friend_face" class="mui-media-object mui-pull-left" src="" 
			            	style="border-radius: 8%;line-height: 50px;max-width: 50px;height: 50px;">
			            <div class="mui-media-body">
			               	<label id="lab_friend_nickname"></label>
			                <p id="p_friend_username" class="mui-ellipsis"></p>
			            </div>
			        </a>
			    </li>
			</ul>
			
			<br />
			<div style="text-align: center;">
				<button id="btn_add_friend" type="button" class="mui-btn mui-btn-block" 
					style="color: white;width: 90%;display: inline;padding: 12px 0;border-radius: 5px;">添加到通讯录</button>
				<!--<button id="btn_back" type="button" class="mui-btn mui-btn-block" 
					style="width: 90%;display: inline;padding: 12px 0">返回</button>-->
			</div>
			
		</div>
		
		<script type="application/javascript" src="../js/app.js"></script>
		<script type="text/javascript">
			mui.init({
				swipeBack:true //启用右滑关闭功能
			});
			mui.plusReady(function(){
				var thisWebview = plus.webview.currentWebview();
				var friendInfo = thisWebview.friendInfo;
				var fr_user_info = thisWebview.fr_user_info;
				if(friendInfo!=null){
					var img_friend_face = document.getElementById("img_friend_face");
					img_friend_face.src = friendInfo.faceImg;
					var lab_friend_nickname = document.getElementById("lab_friend_nickname");
					var p_friend_username = document.getElementById("p_friend_username");
					lab_friend_nickname.innerHTML = friendInfo.nickName;
					p_friend_username.innerHTML = friendInfo.userName;
				}
				
				var btn_add_friend = document.getElementById("btn_add_friend");
				btn_add_friend.addEventListener("tap",function(){
					plus.nativeUI.showWaiting("请稍等");
					var url = app.serverUrl + '/u/sendFriendRequest?friendUserName=' + friendInfo.userName + '&myUserId=' + fr_user_info.userId;
					mui.ajax(url,{
						dataType:'json',//服务器返回json格式数据
						type:'post',//HTTP请求类型
						timeout:10000,//超时时间设置为10秒；
						headers:{'Content-Type':'application/json'},	              
						success:function(data){
							plus.nativeUI.closeWaiting();
							if(data.status == 200){
								var userInfo = data.data;
								// 页面跳转
								app.showToast("添加请求发送成功。", "success");
								setTimeout(()=>{
									mui.openWindow("../index.html", "index.html");
								},200)
							}else{
								app.showToast(data.msg, "error");	
							}
						},
						error:function(xhr,type,errorThrown){
							app.Error();
						}
					});
				});
				
			});
		</script>
	</body>

</html>